package com.ajing.logextractor.extractor;

import com.ajing.logextractor.config.ExtractConfig;
import com.alibaba.fastjson2.JSONPath;

public class JsonExtractor extends AbstractExtractor {

    private final String jsonPath;

    public JsonExtractor(String pattern, ExtractConfig subExtractConfig) {
        super(pattern, subExtractConfig);
        this.jsonPath = pattern;
    }

    @Override
    public String extract(String input) {
        Object jsonExtract = JSONPath.extract(input, jsonPath);
        return null == jsonExtract ? "" : String.valueOf(jsonExtract);
    }
}
